package cn.com.backstage.controller.base;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;
import java.text.SimpleDateFormat;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cn.com.api.entity.ApiT_member_partner_task;

import cn.com.api.service.ApiT_member_partner_taskService;

import cn.com.util.*;


public class T_member_partner_taskBaseController {

	private static Logger logger = Logger.getLogger(T_member_partner_taskBaseController.class);
	
	@Autowired
	private ApiT_member_partner_taskService apiT_member_partner_taskService;
	
	/**
	 * 列表
	 * @return
	 */
	@RequestMapping(value = "t_member_partner_task-list")
	public ModelAndView t_member_partner_task_list(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = new ModelAndView("forward:/backstage/t_member_partner_task_list.jsp");
		
		List<ApiT_member_partner_task> t_member_partner_tasks = apiT_member_partner_taskService.findT_member_partner_tasks();
		mv.addObject("t_member_partner_tasks", t_member_partner_tasks);
		
		return mv;
	}
	
	/**
	 * 进入新增或者编辑页面
	 * @return
	 */
	@RequestMapping(value = "t_member_partner_task-add-pre")
	public ModelAndView t_member_partner_task_add_pre(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = new ModelAndView("forward:/backstage/t_member_partner_task_add.jsp");
		//
		if(request.getParameter("id")!=null){
			String id = request.getParameter("id");
			ApiT_member_partner_task t_member_partner_task = apiT_member_partner_taskService.findT_member_partner_taskById(Integer.valueOf(id));
			mv.addObject("t_member_partner_task",t_member_partner_task);
		}
		return mv;
	}

	/**
	 *新增或者编辑
	 * @return
	 */
	@RequestMapping(value = "t_member_partner_task-add")
	public void t_member_partner_task_add(HttpServletRequest request, HttpServletResponse response) throws Exception{
		String id = request.getParameter("id");
		String task_name = request.getParameter("task_name");
		String invite_partner_amount = request.getParameter("invite_partner_amount");
		String invite_entrepreneur_amount = request.getParameter("invite_entrepreneur_amount");
		String advert_money = request.getParameter("advert_money");
		String complete_time = request.getParameter("complete_time");
		String ext1 = request.getParameter("ext1");
		String ext2 = request.getParameter("ext2");
		String ext3 = request.getParameter("ext3");
		String ext4 = request.getParameter("ext4");
		String ext5 = request.getParameter("ext5");
		String award_money = request.getParameter("award_money");
		
		Map<String,Object> map = new HashMap<String,Object>();
		//String id = request.getParameter("id");
		//add
		if(id==null || (id.trim()).equals("")){
			ApiT_member_partner_task t_member_partner_task = new ApiT_member_partner_task();
            /*
		    t_member_partner_task.setId(id);
		    t_member_partner_task.setTask_name(task_name);
		    t_member_partner_task.setInvite_partner_amount(invite_partner_amount);
		    t_member_partner_task.setInvite_entrepreneur_amount(invite_entrepreneur_amount);
		    t_member_partner_task.setAdvert_money(advert_money);
		    t_member_partner_task.setComplete_time(complete_time);
		    t_member_partner_task.setExt1(ext1);
		    t_member_partner_task.setExt2(ext2);
		    t_member_partner_task.setExt3(ext3);
		    t_member_partner_task.setExt4(ext4);
		    t_member_partner_task.setExt5(ext5);
		    t_member_partner_task.setAward_money(award_money);
	        */
			apiT_member_partner_taskService.insertT_member_partner_task(t_member_partner_task);
		}
		//edit
		else{
			ApiT_member_partner_task t_member_partner_task = apiT_member_partner_taskService.findT_member_partner_taskById(Integer.valueOf(id));
	        /*
		    t_member_partner_task.setId(id);
		    t_member_partner_task.setTask_name(task_name);
		    t_member_partner_task.setInvite_partner_amount(invite_partner_amount);
		    t_member_partner_task.setInvite_entrepreneur_amount(invite_entrepreneur_amount);
		    t_member_partner_task.setAdvert_money(advert_money);
		    t_member_partner_task.setComplete_time(complete_time);
		    t_member_partner_task.setExt1(ext1);
		    t_member_partner_task.setExt2(ext2);
		    t_member_partner_task.setExt3(ext3);
		    t_member_partner_task.setExt4(ext4);
		    t_member_partner_task.setExt5(ext5);
		    t_member_partner_task.setAward_money(award_money);
			*/
			apiT_member_partner_taskService.updateT_member_partner_task(t_member_partner_task);
		}
		//
		map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
		map.put(Utils.MESSAGE, "添加成功！");
        JsonUtil.printJson(response, JsonUtil.object2json(map));
	}
	
	/**
	 *删除
	 * @return
	 */
	@RequestMapping(value = "t_member_partner_task-delete")
	public void t_member_partner_task_delete(HttpServletRequest request, HttpServletResponse response) throws Exception{
		
		Map<String,Object> map = new HashMap<String,Object>();
		String id = request.getParameter("id");
		
		//delete
		int ret_i =	apiT_member_partner_taskService.deleteT_member_partner_task(Integer.valueOf(id));
		
		//
		if(ret_i > 0){
			map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "删除成功！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}
	
}



